package com.minhua.jijiehao2.http

import com.minhua.jijiehao2.bean.BaseBean
import com.minhua.jijiehao2.utils.ActivityTaskManager
import com.minhua.jijiehao2.utils.LoadingDialogUtil
import com.minhua.jijiehao2.view.LoadingDialog
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * @author moo
 * @date 2017/11/14.
 * @describe 请求控制类
 */

class HttpController<T> {
    fun doHttp(observable: Observable<BaseBean<T>>, baseSubscriber: BaseSubscriber<T>, showDialog: Boolean = true) {
        if (showDialog) {
            LoadingDialogUtil.showDialog(ActivityTaskManager.getActivityTaskManager().currentActivity(),
                    LoadingDialog.OnCancel { baseSubscriber.cancel() })
        }
        observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(baseSubscriber)
    }

}
